<template>
  <div id="cluereport">
    <el-dialog
      :title="dialogTitle"
      :visible.sync="formShowVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <formShow :projectId="projectId" :timestamp="timestamp" :readOnly="readonly" @addData="addData" :item="item"></formShow>
    </el-dialog>
    <el-dialog
      title="查看纪检机构信息"
      :visible.sync="unitInfoVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <unitFormShow :projectId="projectId" :timestamp="timestamp" :readOnly="readonly" @saveUnitData="saveUnitData" :unitData="unitData" />
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/unitReport' }">统计填报</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/unitReport/unitList/'+ project.id}">{{project.title}}</el-breadcrumb-item>
      <el-breadcrumb-item>查看</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <h1>单位名称：{{unitname}}</h1>
      <el-button type="primary" @click="backUnit"  icon="el-icon-back" style="float:right;margin:10px 5px;">返回</el-button>
      <div style="line-height:200%;margin:10px;">纪检机构名称：{{deptName}}
      </div>
    </section>
    <section class="unitbox" style="margin-top:10px">
    <!-- <section style="margin-top:10px"> -->
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border
        ref="multipleTable"
        >
        <el-table-column type="index" label="序号" width="60" align="center" class-name="tableth">
        </el-table-column>
        <el-table-column label="姓名" width="80" prop="realname" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).realname}}
          </template>
        </el-table-column>
        <el-table-column label="性别" width="80" prop="sex" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).sex}}
          </template>
        </el-table-column>
        <el-table-column label="民族" width="100" prop="nation" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).nation}}
          </template>
        </el-table-column>
        <el-table-column label="人员身份" prop="identity" width="100" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).identity}}
          </template>
        </el-table-column>
        <el-table-column label="出生年月" prop="birthday" width="100" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).birthday}}
          </template>
        </el-table-column>
        <el-table-column label="年龄" prop="age" width="80" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).age}}
          </template>
        </el-table-column>
        <el-table-column label="政治面貌" prop="politicalAppearance" width="150" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).politicalAppearance}}
          </template>
        </el-table-column>
        <el-table-column label="毕业院校及专业" prop="school">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).school}}
            {{JSON.parse(scope.row.dataJson).major}}
          </template>
        </el-table-column>
        <el-table-column label="最高学历" align="center" prop="education" width="150">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).education}}
          </template>
        </el-table-column>
        <el-table-column label="职务职级" width="250" prop="job" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).job.map(item => `${item.name}（${item.level}）`).join('，')}}
          </template>
        </el-table-column>
        <el-table-column label="所患疾病" width="150" prop="shjb" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).shjb}}
          </template>
        </el-table-column>
        <el-table-column label="伤残缘由" width="150" prop="scyy" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).scyy}}
          </template>
        </el-table-column>
        <el-table-column label="程度" width="150" prop="sccd" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).sccd}}
          </template>
        </el-table-column>
        <!-- <el-table-column label="个人奖励数量" width="120" prop="awards" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.dataJson).awards?JSON.parse(scope.row.dataJson).awards.length:0}}
          </template>
        </el-table-column> -->
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button @click="edit(scope.$index,scope.row)" type="primary" size="mini" style="margin:10px 0 10px 5px">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
import formShow from './customFormShow2025'
import unitFormShow from './customUnitFormShow2025'
export default {
  components: {
    formShow, unitFormShow
  },
  data () {
    return {
      deptName: '',
      unitData: {},
      unitInfoVisible: false,
      total: 0,
      pageNum: 1,
      pageSize: 20,
      totalnum: 0,
      Isace: true,
      Sortkey: '',
      index: -1,
      formShowVisible: false,
      timestamp: '',
      unitId: null,
      deptId: null,
      projectId: null,
      dialogTitle: '查看',
      items: [],
      unitname: '',
      project: {},
      listLoading: true,
      dataLoading: true,
      tableHeight: 100,
      list: [
      ],
      changeSizeFlag: false,
      readonly: true,
      item: {},
      fileIds: []
    }
  },
  methods: {
    backUnit () {
      this.$router.push('/unitReport/customUnitProjectDetail2025/' + this.unitId)
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getProjectDataDetail(this.unitId)
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getProjectDataDetail(this.unitId)
      }
    },
    saveUnitData () {
    },
    addData (item) {
      this.formShowVisible = false
      this.fileIds = []
      Object.keys(item).forEach(key => {
        JSON.parse(this.project.reportTemplate).columns.find(tempitem => { // 从模板中找出模板项为该key的配置项
          if (tempitem.title === key && tempitem.type === 'upload') { // 并且该配置项为文件类型
            if (item[key].length > 0) {
              this.fileIds = [...this.fileIds, ...item[key].map(files => files.id)]
            }
          }
        })
      })
      let para = {
        dataJson: item,
        fileIds: this.fileIds,
        projectDataId: parseInt(this.unitId),
        ageDate: '20250630'
      }
      this.$http
        .post(this.$http.defaults.unitReportAPI + `api/project/saveDataItem2025`, para)
        .then(response => {
          if (response.data.success) {
            this.fileIds = []
            this.$message({
              message: '保存成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: '保存失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络保存失败:' + error,
            type: 'error'
          })
        })
    },
    showUnitInfo () {
      this.timestamp = new Date().getTime()
      this.unitInfoVisible = true
    },
    edit (index, item) {
      this.index = index
      this.timestamp = new Date().getTime()
      this.formShowVisible = true
      this.item = item
    },
    getProjectDetail (id) {
      this.dataLoading = true
      this.listLoading = true
      this.$http
        .get(this.$http.defaults.unitReportAPI + `api/project/getProjectById?id=` + id)
        .then(response => {
          this.project = response.data.result
          this.dataLoading = false
          this.listLoading = false
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.dataLoading = false
          this.listLoading = false
        })
    },
    getProjectDataDetail (id) {
      this.$http
        .get(this.$http.defaults.unitReportAPI + `api/project/getProjectDataById?id=` + id)
        .then(response => {
          this.unitname = response.data.result.unitName
          this.projectId = response.data.result.projectId
          this.getProjectDetail(this.projectId)
          this.getList(id)
          if (response.data.result.dataJson) {
            this.unitData = JSON.parse(response.data.result.dataJson)
            this.deptName = this.unitData.find(item => item.id === this.deptId).deptName
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    getList (id) {
      let para = {
        projectDataId: id,
        orderField: this.Sortkey,
        orderType: this.Isace,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        deptId: this.deptId,
        liveFlag: 1
      }
      this.$http
        .post(this.$http.defaults.unitReportAPI + `api/project/queryDataItemByPage2005`, para)
        .then(response => {
          this.listLoading = false
          this.list = response.data.result.records
          this.totalnum = response.data.result.total
          this.changeSizeFlag = false
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      let myheight = 295

      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - myheight
      })
    }
  },
  mounted () {
    this.unitId = this.$route.params.id.split(',')[0]
    this.deptId = this.$route.params.id.split(',')[1]
    this.getProjectDataDetail(this.unitId)
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
#cluereport .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .unitbox .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .unitbox .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #cluereport .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
</style>
<style scoped>
  #cluereport .el-button{
    color:#fff !important;
  }
  #cluereport h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #cluereport .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .unitbox{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
